package com.yxq.mdt.app.modules.personal.model;

import com.yxq.mdt.app.base.ibase.IBaseModel;
import com.yxq.mdt.app.modules.personal.bean.RealNameResultBean;
import com.yxq.mdt.app.net.ApiModel;
import com.yxq.mdt.app.net.BaseObserver;
import com.yxq.mdt.app.net.RetrofitFactory;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.RequestBody;
import retrofit2.http.Body;

/**
 * @author L
 * @time 2019-12-03
 * @describe
 */
public class RealNameModel implements IBaseModel {

    public void saveRealName(String code, String resultCode, String identityCardName, String identityCardNo, ApiModel.CommonCallback<String> callback) {
        RetrofitFactory.getJavaRetrofit().create(RealNameAPI.class)
                .saveRealName(code, resultCode, identityCardName, identityCardNo)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<String>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(String respBase) {
                        callback.onSuccess(respBase);
                    }
                });
    }

    public void saveOpenChat(RequestBody body, ApiModel.CommonCallback<String> callback) {
        RetrofitFactory.getJavaRetrofit().create(RealNameAPI.class)
                .saveOpenChat(body)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<String>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(String respBase) {
                        callback.onSuccess(respBase);
                    }
                });
    }

    public void saveCard(String identityCardName, String identityCardNo, String identityCardFront, String identityCardBack, ApiModel.CommonCallback<String> callback) {
        RetrofitFactory.getJavaRetrofit().create(RealNameAPI.class)
                .saveCard(identityCardName, identityCardNo, identityCardFront, identityCardBack)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<String>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(String respBase) {
                        callback.onSuccess(respBase);
                    }
                });
    }

    public void getCardNoAndName(ApiModel.CommonCallback<RealNameResultBean> callback) {
        RetrofitFactory.getJavaRetrofit().create(RealNameAPI.class)
                .getCardNoAndName()
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<RealNameResultBean>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(RealNameResultBean respBase) {
                        callback.onSuccess(respBase);
                    }
                });
    }

    @Override
    public void onDestroy() {

    }
}
